<template>
  <div class="home-mastery">
    <h2>达人歌单</h2>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item,index) in listData" :key="index">
          <div class="cover">
            <van-image :src="item.cover" radius="1rem"/>
            <span class="num">{{ item.listen_num | numFilter(1) }}万</span>
          </div>
          <span class="name">{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>


<script>
import {getMasterySingingList} from '@/api/homeApi'
import {betterScrollHorizontal} from "@/common/betterScroll";

export default {
  data() {
    return {
      listData: []
    }
  },
  created() {
    this.getSongListData()
  },
  methods: {
    //获取推荐歌单数据
    async getSongListData() {
      const {list} = await getMasterySingingList()
      this.listData = list
      betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10) //调用横向滚动的方法
    },

  },
}
</script>

<style scoped lang="less">
.home-mastery{
  h2 {
    margin-left: 0.2rem;
  }
  .wrapper {
    width: 100%;
    overflow: hidden;
    .content{
      li {
        display: inline-block;
        width: 10rem;
        vertical-align: top;
        padding: 0.1rem;
        box-sizing: border-box;
        .cover {
          position: relative;
          .num {
            position: absolute;
            right: 0.2rem;
            bottom: 0.3rem;
            background-color: rgba(255, 255, 255, .4);
            color: white;
            font-size: 14px;
            border-radius: 1rem;
            padding-left: 0.5rem;
            padding-right: 0.5rem;
            box-sizing: border-box;
            display: inline-block;
          }
        }
        .name {
          display: inline-block;
          width: 100%;
          font-size: 0.8rem;
          color: #54493B;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}
</style>
